import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

// 公开路由
const publicRoutes = [
  {
    path: '/',
    redirect: '/layout'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/index.vue'),
  },
  {
    path: '/layout',
    name: 'layout',
    component: () => import('../components/layout/index.vue'),
    redirect: 'profile',
    children: [
      {
        path: '/profile',
        name: 'profile',
        component: () => import('../views/profile/index.vue'),
        meta: {
          title: 'profile',
          icon: 'icon-gerenzhongxin',
        }
      },
      {
        path: '/404',
        name: '404',
        component: () => import('../views/error-page/404.vue')
      },
      {
        path: '/401',
        name: '401',
        component: () => import('../views/error-page/401.vue')
      },
    ]
  },
];



// 私有路由表
const privateRoutes = [
  {
    path: '/user',
    component: () => import('../components/layout/index.vue'),
    meta: {
      title: 'user',
      icon: 'icon-users'
    },
    redirect: '/user/manage',
    children: [
      {
        path: '/user/manage',
        component: () => import('../views/user-manage/index.vue'),
        meta: {
          title: 'userManage',
          icon: 'icon-yuangongguanli',
        }
      },
      {
        path: '/user/role',
        component: () => import('../views/role-list/index.vue'),
        meta: {
          title: 'roleList',
          icon: 'icon-tongxunlu',
        }
      },
      {
        path: '/user/permission',
        component: () => import('../views/permission-list/index.vue'),
        meta: {
          title: 'permissionList',
          icon: 'icon-quanxianguanli',
        }
      },
      {
        path: '/user/info/:id',
        name: 'userInfo',
        component: () => import('../views/user-info/index.vue'),
        meta: {
          title: 'userInfo',
        }
      },
      {
        path: '/user/import',
        name: 'import',
        component: () => import('../views/import/index.vue'),
        meta: {
          title: 'excelImport',
        }
      },
    ]
  },
  {
    path: '/article',
    component: () => import('../components/layout/index.vue'),
    meta: {
      title: 'article',
      icon: 'icon-describe'
    },
    redirect: '/article/ranking',
    children: [
      {
        path: '/article/ranking',
        component: () => import('../views/article-ranking/index.vue'),
        meta: {
          title: 'articleRanking',
          icon: 'icon-liebiao',
        }
      },
      {
        path: '/article/create',
        component: () => import('../views/article-create/index.vue'),
        meta: {
          title: 'articleCreate',
          icon: 'icon-bianjiwenzhang_huaban',
        }
      },
      {
        path: '/article/:id',
        component: () => import('../views/article-detail/index.vue'),
        meta: {
          title: 'articleDetail',
        }
      },
      {
        path: '/article/editor/:id',
        component: () => import('../views/article-create/index.vue'),
        meta: {
          title: 'articleEditor',
        }
      },
    ]
  },
];









const router = new VueRouter({
  routes: [...publicRoutes, ...privateRoutes],
});

// const originalPush = VueRouter.prototype.push

// VueRouter.prototype.push = function pus(location) {
//   return originalPush.call(this.push, location).catch(err => err)
// }


export default router;
